package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.PayWayBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.SecurityCenterActivity;

import java.util.List;


public class SecurityCenterActivityPresenter extends BasePresenter<SecurityCenterActivity> {

    public void getPayType() {
        httpService.getPayType()
                .execute(new JsonCallBack<HttpData<List<PayWayBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<List<PayWayBean>>> response) {
                        HttpData<List<PayWayBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.setPayType(httpData.getData());
                        }
                    }
                });
    }

    public void togglePay(String id, boolean status) {
        httpService.togglePayType(id, status)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.togglePayTypeSuccess();
                        }
                    }
                });
    }

    // 谷歌认证通过后  开启
    public void openGoogle(String id, String code) {
        httpService.openChrome(id, code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.toggleShopSuccess();
                        }
                    }
                });
    }

    public void closeGoogle(String id, String code, String telCode) {
        httpService.closeChrome(id, code, telCode)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.toggleShopSuccess();
                        }
                    }
                });
    }
    // 获取验证码
    public void sendCode(String mobile) {
        httpService.sendCode(mobile, "1", "3", mobile)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCodeError();
                        super.onError(response);
                    }
                });
    }
}
